﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ETM.Business.Handlers;
using ETM.Business.Models;
using Newtonsoft.Json;

namespace ETM.Web.Controllers
{
    public class ValuesController : ApiController
    {
        // GET api/values
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/values
        public Task Post([FromBody]string value)
        {

            if(!value.StartsWith("DELETE"))
            {
                var newTask = (Task)JsonConvert.DeserializeObject(value, typeof(Task));

                if(newTask.TaskId != "000")
                {
                    var createdTask = new EditTask().AddOne(newTask);
                    return createdTask;
                }
            }
            

            else
            {
                var taskId = value.Replace("DELETE", string.Empty);

                var deleteTask = new EditTask().DeleteOne(taskId);
                
            }
            return null;
            
        }

        // PUT api/values/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        public string Delete(int id)
        {
            return id.ToString();
        }
    }
}